#include "StdAfx.h"
#include "WECalendar.h"
#include "WceUiDlg.h"

#define CALENDAR_TIMER_ID	1
#define CALENDAR_TIMER_LEN	5000

CWECalendar::CWECalendar(void)
{
	m_pDay = NULL;
}

CWECalendar::~CWECalendar(void)
{
}


void CWECalendar::OnInitLayer()
{
	m_pDay = GetChildByName(L"day");
	ASSERT(NULL != m_pDay);

	SetTimer(CALENDAR_TIMER_ID, CALENDAR_TIMER_LEN);
	OnTimer(CALENDAR_TIMER_ID);

	EnableHMove(TRUE);
	EnableVMove(TRUE);

	CRect rc;
	GetClientRect(&rc);
	SetHLimit(0, WceUiGetScreenWidth() - rc.Width());
	SetVLimit(0, WceUiGetScreenHeight() - rc.Height() - 15);
}

void CWECalendar::OnLButtonDown(UINT nFlags, POINT point)
{
	CWceUiLayer *pDeskTop = GetDlg()->GetChildByName(L"desktop");
	MoveBefore(pDeskTop);
	CWEMoveAbleStatic::OnLButtonDown(nFlags, point);
}


void CWECalendar::OnTimer(WORD wIDEvent)
{
	if (wIDEvent == CALENDAR_TIMER_ID)
	{
		SYSTEMTIME st;
		GetLocalTime(&st);

		TCHAR szWeek[32];
		TCHAR szText[32];

		switch(st.wDayOfWeek)
		{
		case 0: _tcscpy(szWeek, _T("Sunday")); break;
		case 1: _tcscpy(szWeek, _T("Monday")); break;
		case 2: _tcscpy(szWeek, _T("Tuesday")); break;
		case 3: _tcscpy(szWeek, _T("Wednesday")); break;
		case 4: _tcscpy(szWeek, _T("Thursday")); break;
		case 5: _tcscpy(szWeek, _T("Friday")); break;
		case 6: _tcscpy(szWeek, _T("Saturday")); break;
		default:ASSERT(FALSE); break;
		}

		SetText(szWeek);

		_stprintf(szText, L"%d", st.wDay);
		ASSERT(NULL != m_pDay);
		m_pDay->SetText(szText);
	}
}